﻿<% Response.Charset="UTF-8" %>
<!--#include file="md5.asp" -->
<%
fields=request.form("fields")
nick=request.form("nick") + ""
keyword=request.form("keyword") + ""
v="1.0"
appkey=request.form("appkey")
appsecret=request.form("appsecret")
topurl=request.form("topurl")
timestamp=getDate(date,"yyyy-mm-dd")&" "&getTime(time,"hh:mm:ss")
timestamp2=server.URLEncode(timestamp)
method=request.form("method")
format=request.form("format")

sign=appsecret&"app_key"&appkey&"fields"&fields&"format"&format&"keyword"&keyword&"method"&method&"nick"&nick&"timestamp"&timestamp&"v"&v

top_sign=md5(sign)

postdatastr="app_key="&appkey&"&fields="&fields&"&format="&format&"&keyword="&server.URLEncode(keyword)&"&method="&method&"&nick="&server.URLEncode(nick)&"&sign="&top_sign&"&timestamp="&timestamp2&"&v="&v
REST_RESPONSE = PostHttpPage(topurl, postdatastr)

response.Write(Server.HtmlEncode(REST_RESPONSE))

Function PostHttpPage(PostUrl,PostData) 
	Dim xmlHttp 
	Dim RetStr      
	Set xmlHttp = CreateObject("Msxml2.ServerXMLHTTP")  
	xmlHttp.Open "POST", PostUrl, False
	XmlHTTP.setRequestHeader "Content-Length", Len(PostData) 
	xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"
	xmlHttp.Send PostData
	If Err.Number <> 0 Then 
		Set xmlHttp=Nothing
		PostHttpPage = "$False$"
		Exit Function
	End If
	PostHttpPage=bytesToBSTR2(xmlHttp.responseBody,"utf-8")
	Set xmlHttp = nothing
End Function

Function BytesToBstr2(strBody,CodeBase)
	   dim obj
	   set obj=Server.CreateObject("Adodb.Stream")
	   obj.Type=1
	   obj.Mode=3
	   obj.Open
	   obj.Write strBody
	   obj.Position=0
	   obj.Type=2
	   obj.Charset=CodeBase
	   BytesToBstr2=obj.ReadText
	   obj.Close
	   set obj=nothing
End Function

Function getDate(var_date,var_format)
  if var_format="yyyy-mm-dd" then
   var_year=year(var_date)
   var_month=month(var_date)
   var_day=day(var_date)
   if (var_month>=0 and var_month<=9) then
      var_month="0"&var_month  
   end if 
  
   if (var_day>=0 and var_day<=9) then
       var_day="0"&var_day
   end if 
    str_date=var_year&"-"&var_month&"-"&var_day
        getDate=str_date
  
  end if
End Function

Function getTime(var_time,var_format)
  if var_format="hh:mm:ss" then
    var_hour=hour(time)
        var_minute=minute(time)
        var_second=second (time)
        
        if (var_hour>=0 and var_hour<=9) then
             var_hour="0"&var_hour
        end if 
        
        if (var_minute>=0 and var_minute<=9) then
             var_minute="0"&var_minute
        end if 
        
        if (var_second>=0 and var_second<=9) then
             var_second="0"&var_second
        end if
        
        str_time=var_hour&":"&var_minute&":"&var_second
    getTime=str_time
  end if

End Function

%>